/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package yinshi.j2d;

import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.Rectangle2D;

/**
 *
 * @author yinshi
 */
public class Shape2D extends Leaf {

    private Shape shape = new Rectangle2D.Double(-5, -5, 10, 10);
    private Paint foreground = Node.DEFAULT_FOREGROUND;
    private Paint background = Node.DEFAULT_BACKGROUND;
    private Stroke stroke = Node.DEFAULT_STROKE;

    public Shape2D() {
    }

    public Shape getShape() {
        return shape;
    }

    public void setShape(Shape shape) {
        this.shape = shape;
    }

    public Paint getForeground() {
        return foreground;
    }

    public void setForeground(Paint foreground) {
        this.foreground = foreground;
    }

    public Paint getBackground() {
        return background;
    }

    public void setBackground(Paint background) {
        this.background = background;
    }

    public Stroke getStroke() {
        return stroke;
    }

    public void setStroke(Stroke stroke) {
        this.stroke = stroke;
    }

    public void paint(Graphics2D g, int x, int y, int width, int height) {
        if (shape == null) {
            return;
        }

        Paint temp_paint = g.getPaint();
        Stroke temp_stroke = g.getStroke();


        g.setStroke(this.stroke);

        if (background != null) {
            g.setPaint(background);
            g.fill(shape);
        }
        if (foreground != null) {
            g.setPaint(foreground);
            g.draw(shape);
        }

        g.setPaint(temp_paint);
        g.setStroke(temp_stroke);
    }
}
